<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: 当燃      
 * Date: 2015-09-09
 */

namespace Admin\Controller;

use Admin\Logic\UsersLogic;
use Think\AjaxPage;
use Think\Page;

class UserController extends BaseController {

    public function index(){
        $this->display();
    }

    /**
     * 会员列表
     */
    public function ajaxindex(){
        // 搜索条件
        $condition = array();

        $email=I('email') ? $condition['email'] = I('email') : false;
       $mobile=I('mobile');
        $condition['mobile']=array('like',"%$mobile%");
        $tguser_input=I('tguser');
		$bz=I('bz') ? $condition['bz'] = I('bz') : false;   
		
        $nickname=I('nickname');
        $condition['nickname']=array('like',"%$nickname%");
        $tjr_cs=I('tjr_cs') ? $condition['tjr_cs'] = I('tjr_cs') : false;
        $sort_order = I('order_by').' '.I('sort'); 
		
         $timegap = I('shijian');
         if($timegap){
            $begin = strtotime($timegap);
            $end = strtotime($timegap)+86399;
            $condition['reg_time'] = array('between',"$begin,$end");
        }
        $is_admin=session();

        $id=$is_admin['admin_id'];
        $roleid=M('admin')->field('role_id')->where("admin_id=$id")->find();
        $roleid=$roleid['role_id'];

        $condition['ty_users.roleid']=$roleid;

	    $model = M('users');
        $count = $model->field('ty_users.*,ty_store.store_name as store_name')->join('ty_store on ty_users.seller_id=ty_store.store_id' )->where($condition)->count();
        $Page  = new AjaxPage($count,10);
        //  搜索条件下 分页赋值
        if(empty($email)&&empty($mobile)){

            
            $condition['group_id'] = '0';

            $model = M('users');
            $userList = $model->field('ty_users.*,ty_store.store_name as store_name')->join('ty_store on ty_users.seller_id=ty_store.store_id' )->where($condition)->order($sort_order)->limit($Page->firstRow.','.$Page->listRows)->select();
            foreach ($userList as $key => &$value) {

                $user=explode(",", $value['bz']);
                $value['bz']=$user;
                $tjr_name=M('users')->field('nickname')->where(array('user_id'=>$value['tjr_id']))->find();
                $value['tjr_name']=$tjr_name['nickname'];
                $tui=M('users')->where(array('user_id'=>$value['tuixiao_id']))->find();
                $value['tgy']=$tui['nickname'];
             } 
            

           
        }

        $model = M('users');

        $count = $model->field('ty_users.*,ty_store.store_name as store_name')->join('ty_store on ty_users.seller_id=ty_store.store_id' )->where($condition)->count();
        $Page  = new AjaxPage($count,10);
        //  搜索条件下 分页赋值
        foreach($condition as $key=>$val) {
            $Page->parameter[$key]   =   urlencode($val);
        }
        $condition['bz']=array('like','%'.$bz.'%');
        $condition['tjr_cs']=array('egt',$tjr_cs);
        $condition['group_id']='0';
        $userList = $model->field('ty_users.*,ty_store.store_name as store_name')->join('ty_store on ty_users.seller_id=ty_store.store_id' )->where($condition)->order($sort_order)->limit($Page->firstRow.','.$Page->listRows)->select();
       //$userList = $model->where($condition)->order($sort_order)->limit($Page->firstRow.','.$Page->listRows)->select();

     

        $user_id_arr = get_arr_column($userList, 'user_id');
        foreach ($userList as $key => &$value) {
            $tjr_name=M('users')->field('nickname')->where(array('user_id'=>$value['tjr_id']))->find();
            $value['tjr_name']=$tjr_name['nickname'];
             $tui=M('users')->where(array('user_id'=>$value['tuixiao_id']))->find();
                $value['tgy']=$tui['nickname'];
        }
        //var_dump($userList);
        if(!empty($user_id_arr))
        {
            $first_leader = M('users')->query("select first_leader,count(1) as count  from __PREFIX__users where first_leader in(".  implode(',', $user_id_arr).")  group by first_leader");
            $first_leader = convert_arr_key($first_leader,'first_leader');
            
            $second_leader = M('users')->query("select second_leader,count(1) as count  from __PREFIX__users where second_leader in(".  implode(',', $user_id_arr).")  group by second_leader");
            $second_leader = convert_arr_key($second_leader,'second_leader');            
            
            $third_leader = M('users')->query("select third_leader,count(1) as count  from __PREFIX__users where third_leader in(".  implode(',', $user_id_arr).")  group by third_leader");
            $third_leader = convert_arr_key($third_leader,'third_leader');            
        }
	
		

        $this->assign('tguser_m',$tguser_m);
        $this->assign('first_leader',$first_leader);
        $this->assign('second_leader',$second_leader);
        $this->assign('third_leader',$third_leader);
                                
        $show = $Page->show();
        $this->assign('userList',$userList);
        $this->assign('page',$show);// 赋值分页输出
        $this->assign('level',M('user_level')->getField('level_id,level_name'));
        $this->display();
    }

    /**
     * 会员详细信息查看
     */
    public function detail(){
        $uid = I('get.id');
        $user = D('users')->where(array('user_id'=>$uid))->find();
		$tuixiao = D('users')->where(array('user_id'=>$user_id))->find();
		$bz1=D('bingzhong')->where(array('cat_id'=>1))->select();
		$bz2=D('bingzhong')->where(array('cat_id'=>2))->select();
		$bz3=D('bingzhong')->where(array('cat_id'=>31))->select();
		$bz4=D('bingzhong')->where(array('cat_id'=>32))->select();
		$bz5=D('bingzhong')->where(array('cat_id'=>33))->select();
		$bz6=D('bingzhong')->where(array('cat_id'=>34))->select();
		$bz7=D('bingzhong')->where(array('cat_id'=>4))->select();
		$bz8=D('bingzhong')->where(array('cat_id'=>5))->select();
		$bz = array($bz1,$bz2,$bz3,$bz4,$bz5,$bz6,$bz7,$bz8);
        //$cishu=M('order_goods')->join('ty_order on ty_order_goods.order_id = ty_order.order_id')->where(array('user_id'=>$uid))->select();
		//var_dump($cishu);
        $sql1="select * from ty_order a ,ty_goods b, ty_order_goods c where a.order_id= c.order_id and c.goods_id=b.goods_id and a.user_id='$uid' and b.good_cishu >'0' and a.order_status =1";
        $Model = M();
        $fuwu = $Model->query($sql1);
		foreach($fuwu as $k => &$v){
			$count =M(liliao)->where(array('user_id'=>$uid,'order_id'=>$v['order_id']))->count();
			$v['sycs']=$v['good_cishu']*$v['goods_num']-$count;
			$v['count']=$count;
		}
		$this->assign('fuwu',$fuwu);
		if(empty($fuwu)){
			
			$user['list']='0';
		}else{
			
			$user['list']='1';
		}
		$tuixiao_id=$user['tuixiao_id'];
        $store_id=$user['seller_id'];
		$tui=M('users')->where(array('user_id'=>$tuixiao_id))->find();

        $seller_info = D('seller')->field('user_id')->where("store_id=".$store_id." and  group_id in(5,7)")->order('group_id desc')->select();
        $seller_ids = array();
        foreach ($seller_info as $key => $value) {
           $seller_ids[] =  $value['user_id'];
        }
        $seller_ids = implode(',', $seller_ids);
        $tgy = D('users')->where("user_id in(".$seller_ids.")")->order('group_id desc')->select(); 
		//var_dump($tui);
        $sql="select * from ty_liliao a ,ty_users b ,ty_store c ,ty_order_goods d where a.store_id=c.store_id and a.czy_id =b.user_id and a.user_id=$uid and d.order_id =a.order_id GROUP BY  a.id DESC limit 0,5 ";     
		//echo $sql;
		$Model = M();
        $result = $Model->query($sql);
        
        $xiaji="select nickname from ty_users where tjr_id=$uid ";
        $xiaxianname=M()->query($xiaji);
        //var_dump($xiaxianname);

        if(!$user)
            exit($this->error('会员不存在'));
        if(IS_POST){
            //  会员信息编辑
			
            $password = I('post.password');
            $password2 = I('post.password2');
			$tizheng1=$_POST['tizheng1'] ? $_POST['tizheng1'] : '0';
            $tizheng2=$_POST['tizheng2'] ? $_POST['tizheng2'] : '0';
            $tizheng3=$_POST['tizheng3'] ? $_POST['tizheng3'] : '0';
            $tizheng4=$_POST['tizheng4'] ? $_POST['tizheng4'] : '0';
            $tizheng5=$_POST['tizheng5'] ? $_POST['tizheng5'] : '0';
			if($tizheng1=='0'){
				$tizheng1='';
			}else{
				$tizheng1=implode(",",$tizheng1);
				$_POST['tizheng1']=$tizheng1;
			}
			if($tizheng2=='0'){
				$tizheng2='';
			}else{
				$tizheng2=implode(",",$tizheng2);
				$_POST['tizheng2']=$tizheng2;
			}
			if($tizheng3=='0'){
				$tizheng3='';
			}else{
				$tizheng3=implode(",",$tizheng3);
				$_POST['tizheng3']=$tizheng3;
			}
			if($tizheng4=='0'){
				$tizheng4='';
			}else{
				$tizheng4=implode(",",$tizheng4);
				$_POST['tizheng4']=$tizheng4;
			}
			if($tizheng5=='0'){
				$tizheng5='';
			}else{
				$tizheng5=implode(",",$tizheng5);
				$_POST['tizheng5']=$tizheng5;
			}
            
            if($password != '' && $password != $password2){
                exit($this->error('两次输入密码不同'));
            }
            if($password == '' && $password2 == ''){
                unset($_POST['password']);
            }else{
                $_POST['password'] = encrypt($_POST['password']);
            }
            
            $row = M('users')->where(array('user_id'=>$uid))->save($_POST);
            $tuixiao_id=$_POST['tuixiao_id'];
            M('order')->where(array('user_id'=>$uid))->save(array('tuiguangid'=>$tuixiao_id));
            if($row)
                exit($this->success('修改成功'));
            exit($this->error('未作内容修改或修改失败'));
        }
        
        $user['first_lower'] = M('users')->where("first_leader = {$user['user_id']}")->count();
        $user['second_lower'] = M('users')->where("second_leader = {$user['user_id']}")->count();
        $user['third_lower'] = M('users')->where("third_leader = {$user['user_id']}")->count();
		$tx=M('user_tx')->where(array('user_id'=>$uid))->select();
		$this->assign('bz',$bz);
		$this->assign('tuixiao',$tuixiao);
        $this->assign('tx',$tx);
		$this->assign('tui',$tui);
        $this->assign('tgy',$tgy);
        $this->assign('user',$user);
        $this->assign('xiaxianname',$xiaxianname);
        $this->assign('result',$result);
        $this->display();
    }
    
    
    public function add_user(){
		 $storename=M('store')->select();
		$list = D('users')->where(array('group_id'=>3))->order('group_id desc')->select();
		$bz1=D('bingzhong')->where(array('cat_id'=>1))->select();
		$bz2=D('bingzhong')->where(array('cat_id'=>2))->select();
		$bz3=D('bingzhong')->where(array('cat_id'=>31))->select();
		$bz4=D('bingzhong')->where(array('cat_id'=>32))->select();
		$bz5=D('bingzhong')->where(array('cat_id'=>33))->select();
		$bz6=D('bingzhong')->where(array('cat_id'=>34))->select();
		$bz7=D('bingzhong')->where(array('cat_id'=>4))->select();
		$bz8=D('bingzhong')->where(array('cat_id'=>5))->select();
		$bz = array($bz1,$bz2,$bz3,$bz4,$bz5,$bz6,$bz7,$bz8);
    	if(IS_POST){
    		$data = I('post.');
            $reg_time=$_POST['reg_time'];
            if($reg_time){
                $data['reg_time']=strtotime($reg_time);
            }else{
                $data['reg_time']=time();
            }
            $tizheng1=$_POST['tizheng1'] ? $_POST['tizheng1'] : '0';
            $tizheng2=$_POST['tizheng2'] ? $_POST['tizheng2'] : '0';
            $tizheng3=$_POST['tizheng3'] ? $_POST['tizheng3'] : '0';
            $tizheng4=$_POST['tizheng4'] ? $_POST['tizheng4'] : '0';
            $tizheng5=$_POST['tizheng5'] ? $_POST['tizheng5'] : '0';
			if($tizheng1=='0'){
				$tizheng1='';
			}else{
				$tizheng1=implode(",",$tizheng1);
				$data['tizheng1']=$tizheng1;
			}
			if($tizheng2=='0'){
				$tizheng2='';
			}else{
				$tizheng2=implode(",",$tizheng2);
				$data['tizheng2']=$tizheng2;
			}
			if($tizheng3=='0'){
				$tizheng3='';
			}else{
				$tizheng3=implode(",",$tizheng3);
				$data['tizheng3']=$tizheng3;
			}
			if($tizheng4=='0'){
				$tizheng4='';
			}else{
				$tizheng4=implode(",",$tizheng4);
				$data['tizheng4']=$tizheng4;
			}
			if($tizheng5=='0'){
				$tizheng5='';
			}else{
				$tizheng5=implode(",",$tizheng5);
				$data['tizheng5']=$tizheng5;
			}
            $is_admin=session();

            $id=$is_admin['admin_id'];
            $roleid=M('admin')->field('role_id')->where("admin_id=$id")->find();
            $roleid=$roleid['role_id'];
            $data['roleid']=$roleid;
    		$user_obj = new UsersLogic();
    		$res = $user_obj->addUser($data);
    		if($res['status'] == 1){
    			$this->success('添加成功',U('User/index'));exit;
    		}else{
    			$this->error('添加失败,'.$res['msg'],U('User/index'));
    		}
    	}
		$seller_id=session('seller');
	
		$this->assign('list',$list);
		$this->assign('bz',$bz);
		$this->assign('seller_id',$seller_id);
        $this->assign('storename',$storename);
    	$this->display();
    }

    /**
     * 用户收货地址查看
     */
    public function address(){
        $uid = I('get.id');
        $lists = D('user_address')->where(array('user_id'=>$uid))->select();
        $regionList = M('Region')->getField('id,name');
        $this->assign('regionList',$regionList);
        $this->assign('lists',$lists);
        $this->display();
    }

    /**
     * 删除会员
     */
    public function delete(){
        $uid = I('get.id');
        $row = M('users')->where(array('user_id'=>$uid))->delete();
        if($row){
            $this->success('成功删除会员');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * 账户资金记录
     */
    public function account_log(){
        $user_id = I('get.id');
        //获取类型
        $type = I('get.type');
        //获取记录总数
        $count = M('account_log')->where(array('user_id'=>$user_id))->count();
        $page = new Page($count);
        $lists  = M('account_log')->where(array('user_id'=>$user_id))->order('change_time desc')->limit($page->firstRow.','.$page->listRows)->select();

        $this->assign('user_id',$user_id);
        $this->assign('page',$page->show());
        $this->assign('lists',$lists);
        $this->display();
    }

    /**
     * 账户资金调节
     */
    public function account_edit(){
        $user_id = I('get.id');
        if(!$user_id > 0)
            $this->error("参数有误");
        if(IS_POST){
            //获取操作类型
            $m_op_type = I('post.money_act_type');
            $user_money = I('post.user_money');
            $user_money =  $m_op_type ? $user_money : 0-$user_money;

            $p_op_type = I('post.point_act_type');
            $pay_points = I('post.pay_points');
            $pay_points =  $p_op_type ? $pay_points : 0-$pay_points;

            $f_op_type = I('post.frozen_act_type');
            $frozen_money = I('post.frozen_money');
            $frozen_money =  $f_op_type ? $frozen_money : 0-$frozen_money;

            $desc = I('post.desc');
            if(!$desc)
                $this->error("请填写操作说明");


             $store_id = M('users')->field('seller_id')->where(array('user_id'=>$user_id))->find();
            $diquid = M('store')->field('roleid')->where(array('store_id'=>$store_id['seller_id']))->find();
      
            if(accountLog($user_id,$user_money,$pay_points,$desc,$store_id['seller_id'],$diquid['roleid'])){
                $this->success("操作成功",U("Admin/User/account_log",array('id'=>$user_id)));
            }else{
                $this->error("操作失败");
            }
            exit;
        }
      
        $this->assign('user_id',$user_id);
        $this->display();
    }
    
    public function recharge(){
        $timegap = I('timegap');
    	$nickname = I('nickname');
    	$map = array();
    	if($timegap){
    		$gap = explode(' - ', $timegap);
    		$begin = $gap[0];
    		$end = $gap[1];
    		$map['ctime'] = array('between',array(strtotime($begin),strtotime($end)));
    	}
    	if($nickname){
    		$map['nickname'] = array('like',"%$nickname%");
    	}  
    	$count = M('recharge')->where()->count();
    	$page = new Page($count);
    	$lists  = M('recharge')->where()->order('ctime desc')->limit($page->firstRow.','.$page->listRows)->select();
    	$this->assign('page',$page->show());
    	$this->assign('lists',$lists);
    	$this->display();
    }
    
    public function level(){
    	$act = I('GET.act','add');
    	$this->assign('act',$act);
    	$level_id = I('GET.level_id');
    	$level_info = array();
    	if($level_id){
    		$level_info = D('user_level')->where('level_id='.$level_id)->find();
    		$this->assign('info',$level_info);
    	}
    	$this->display();
    }
    
    public function levelList(){
    	$Ad =  M('user_level');
    	$res = $Ad->where('1=1')->order('level_id')->page($_GET['p'].',10')->select();
    	if($res){
    		foreach ($res as $val){
    			$list[] = $val;
    		}
    	}
    	$this->assign('list',$list);
    	$count = $Ad->where('1=1')->count();
    	$Page = new \Think\Page($count,10);
    	$show = $Page->show();
    	$this->assign('page',$show);
    	$this->display();
    }
    
    public function levelHandle(){
    	$data = I('post.');
    	if($data['act'] == 'add'){
    		$r = D('user_level')->add($data);
    	}
    	if($data['act'] == 'edit'){
    		$r = D('user_level')->where('level_id='.$data['level_id'])->save($data);
    	}
    	 
    	if($data['act'] == 'del'){
    		$r = D('user_level')->where('level_id='.$data['level_id'])->delete();
    		if($r) exit(json_encode(1));
    	}
    	 
    	if($r){
    		$this->success("操作成功",U('Admin/User/levelList'));
    	}else{
    		$this->error("操作失败",U('Admin/User/levelList'));
    	}
    }

    /**
     * 搜索用户名
     */
    public function search_user()
    {
        $search_key = trim(I('search_key'));        
        if(strstr($search_key,'@'))    
        {
            $list = M('users')->where(" email like '%$search_key%' ")->select();        
            foreach($list as $key => $val)
            {
                echo "<option value='{$val['user_id']}'>{$val['email']}</option>";
            }                        
        }
        else
        {
            $list = M('users')->where(" mobile like '%$search_key%' ")->select(); 
            $listu = array();
            foreach($list as $key => $val)
            {
                $val['option'] =  "<option value='{$val['user_id']}'>{$val['mobile']}</option>";
                $listu[] = $val;
            }  
            $this->ajaxReturn(json_encode($listu));

        } 
        exit;
    }
    
    /**
     * 搜索推广人员
     */
    public function search_tguser()
    {
        $search_key = trim(I('store_id'));        
        if(strstr($search_key,'@'))    
        {
            $list = M('seller')->where(" store_id = $search_key ")->select();        
            foreach($list as $key => $val)
            {
                echo "<option value='{$val['user_id']}'>{$val['seller_name']}</option>";
            }                        
        }
        else
        {

            $tguser_n = M('seller')->field('user_id')->where("store_id = $search_key and group_id in(5,7)")->select();

            foreach ($tguser_n as $key => $value) {
                $tguser_m[] = $value['user_id'];
            }
            $tguser_sql = implode(',',  $tguser_m);
           
            $tguser = M('users')->field('user_id,nickname')->where("user_id in($tguser_sql)")->select();
            

		
            foreach($tguser as $key => $val)
            {
                echo "<option value='{$val['user_id']}'>{$val['nickname']}</option>";
            }             
        } 
        exit;
    }
    
    /**
     * 分销树状关系
     */
    public function ajax_distribut_tree()
    {
          $list = M('users')->where("first_leader = 1")->select();
          $this->display();
    }

    /**
     *
     * @time 2016/08/31
     * @author dyr
     * 发送站内信
     */
    public function sendMessage()
    {
        $user_id_array = I('get.user_id_array');
        $users = array();
        if (!empty($user_id_array)) {
            $users = M('users')->field('user_id,nickname')->where(array('user_id' => array('IN', $user_id_array)))->select();
        }
        $this->assign('users', $users);
        $this->display();
    }

    /**
     * 发送系统消息
     * @author dyr
     * @time  2016/09/01
     */
    public function doSendMessage()
    {
        $call_back = I('call_back');//回调方法
        $message = I('post.text');//内容
        $type = I('post.type', 0);//个体or全体
        $admin_id = session('admin_id');
        $users = I('post.user');//个体id
        $message = array(
            'admin_id' => $admin_id,
            'message' => $message,
            'category' => 0,
            'send_time' => time()
        );
        if ($type == 1) {
            //全体用户系统消息
            $message['type'] = 1;
            M('Message')->data($message)->add();
        } else {
            //个体消息
            $message['type'] = 0;
            if (!empty($users)) {
                $create_message_id = M('Message')->data($message)->add();
                foreach ($users as $key) {
                    M('user_message')->data(array('user_id' => $key, 'message_id' => $create_message_id, 'status' => 0, 'category' => 0))->add();
                }
            }
        }
        echo "<script>parent.{$call_back}(1);</script>";
        exit();
    }

    /**
     *
     * @time 2016/09/03
     * @author dyr
     * 发送邮件
     */
    public function sendMail()
    {
        $user_id_array = I('get.user_id_array');
        $users = array();
        if (!empty($user_id_array)) {
            $user_where = array(
                'user_id' => array('IN', $user_id_array),
                'email'=> array('neq','')
            );
            $users = M('users')->field('user_id,nickname,email')->where($user_where)->select();
        }
        $this->assign('smtp',tpCache('smtp'));
        $this->assign('users',$users);
        $this->display();
    }

    /**
     * 发送邮箱
     * @author dyr
     * @time  2016/09/03
     */
    public function doSendMail()
    {
        $call_back = I('call_back');//回调方法
        $message = I('post.text');//内容
        $title = I('post.title');//标题
        $users = I('post.user');
        if (!empty($users)) {
            $user_id_array = implode(',', $users);
            $users = M('users')->field('email')->where(array('user_id' => array('IN', $user_id_array)))->select();
            $to = array();
            foreach ($users as $user) {
                if (check_email($user['email'])) {
                    $to[] = $user['email'];
                }
            }
            $res = send_email($to, $title, $message);
            echo "<script>parent.{$call_back}({$res});</script>";
            exit();
        }
    }
	public function liliao(){
        $data['user_id']=$_POST['user_id'];
        $data['czy_id']=$_POST['group_id'];
        $data['order_id']=$_POST['order_id'];
        $store=session('seller');
        $data['store_id']=$store['store_id'];
        $data['shijian']=time();
        $m=M("liliao");
        $result =$m->add($data);
       if($result){
           $this->success('操作成功',true);
       }
	}
    public function export_user(){
        
         $timegap = I('shijian');
         if($timegap){
            $begin = strtotime($timegap);
            $end = strtotime($timegap)+86399;
        }
        $sql = "select * from __PREFIX__users where group_id=0 and seller_id!=0 and reg_time >=$begin and reg_time <=$end order by user_id ";
        $userList = D()->query($sql); 
        $strTable ='<table width="500" border="1">';
        $strTable .= '<tr>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">姓名</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="100">性别</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">年龄</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">家庭住址</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">理疗师</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">店铺</td>';
        $strTable .= '</tr>';
        
        foreach($userList as $k=>$val){
            
            $strTable .= '<tr>';
            $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;'.$val['nickname'].'</td>';
            if($val['sex']=='1'){
                $strTable .= '<td style="text-align:left;font-size:12px;">'.男.' </td>';
            }elseif($val['sex']=='2'){
                $strTable .= '<td style="text-align:left;font-size:12px;">'.女.' </td>';
            }else{
                $strTable .= '<td style="text-align:left;font-size:12px;">'.保密.' </td>';
            }
            
            $strTable .= '<td style="text-align:left;font-size:12px;">'.$val['age'].'</td>';               
            $strTable .= '<td style="text-align:left;font-size:12px;">'.$val['dizhi'].'</td>';
            $sql=M('users')->where("user_id=$val[tuixiao_id]")->find();
            $strTable .= '<td style="text-align:left;font-size:12px;">'.$sql['nickname'].'</td>';
            $sql1=M('store')->where("store_id=$val[seller_id]")->find();
            $strTable .= '<td style="text-align:left;font-size:12px;">'.$sql1['store_name'].'</td>';
            $strTable .= '</tr>';
        }
        $strTable .='</table>';
        unset($orderList);
        downloadExcel($strTable,'users');
        exit();
    }
}